//
//  HWNavigationView.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/24.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit
import SnapKit
class HWNavigationView: UIView {
    var bgView:UIView!
    
    var titleLabel:UILabel!
    
    var backButton:UIButton!
    
    var rightButton:UIButton!
    
    var backButtonClick:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
        initFrame()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
    }
    
}
extension HWNavigationView {
    private func initUI() -> Void {
        
        backgroundColor = .white
       
        layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#E7E7E7", alpha: 0.28).cgColor
        layer.shadowRadius = 4*widthScale
        layer.shadowOpacity = 1
        layer.shadowOffset = CGSize(width: 0, height: 2*widthScale)
        
        titleLabel = HWLabel.createBoldLabel(title: "-", color:"#333333", font: 18)
        addSubview(titleLabel)
        
        backButton = UIButton(type: .custom)
        backButton.setImage(UIImage(named: "fanghui_QC"), for: .normal)
        backButton.addTarget(self, action: #selector(backButtonClick(_:)), for: .touchUpInside)
        addSubview(backButton)
        
        rightButton = UIButton(type: .custom)
        addSubview(rightButton)
        rightButton.isHidden = false
        
    }
    
    private func initFrame() -> Void {
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            if screenHeight >= 812 {
                make.top.equalTo(53)
            }else {
                make.top.equalTo(30)
            }
            
            make.bottom.equalTo(-10)
        }
        
        backButton.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.centerY.equalTo(titleLabel)
        }
    }
}

extension HWNavigationView {
    @objc func backButtonClick(_ button:UIButton) -> Void {
        self.backButtonClick?()
    }
}
